package com.mocoop.activity;

import com.mocoop.ui.MenuItem;
import com.mocoop.ui.MenuItem.OnItemClickListener;

import android.app.Activity;



public class MocoopTabHost implements  OnItemClickListener{
	public MenuItem itemOne, itemTwo, itemFour, itemThree;
	private int currentID = R.id.itemOne;
	private Activity activity;
	private MocoopTabHostListener mocoopTabHostListener;
	

	public MocoopTabHostListener getMocoopTabHostListener() {
		return mocoopTabHostListener;
	}

	public void setMocoopTabHostListener(MocoopTabHostListener mocoopTabHostListener) {
		this.mocoopTabHostListener = mocoopTabHostListener;
	}

	public MocoopTabHost(Activity activity) {
		super();
		this.activity = activity;
		initView();
	}
	
	public void initView(){
		itemOne = (MenuItem) activity.findViewById(R.id.itemOne);
		itemTwo = (MenuItem) activity.findViewById(R.id.itemTwo);
		itemFour = (MenuItem) activity.findViewById(R.id.itemFour);
		itemThree = (MenuItem) activity.findViewById(R.id.itemThree);

		itemOne.setOnClickListener(this);
		itemTwo.setOnClickListener(this);
		itemFour.setOnClickListener(this);
		itemThree.setOnClickListener(this);
	}

	@Override
	public void onImageClick(int id) {
		if (currentID == id) {
			return;
		} else {
			currentID = id;
		}

		if (id == R.id.itemOne) {
			itemOne.setImageResource(R.drawable.tabhost_one_pressed, true);
			itemTwo.setImageResource(R.drawable.tabhost_two, false);
			itemThree.setImageResource(R.drawable.tabhost_three, false);
			itemFour.setImageResource(R.drawable.tabhost_four, false);
		} else if (id == R.id.itemTwo) {
			itemOne.setImageResource(R.drawable.tabhost_one, false);
			itemTwo.setImageResource(R.drawable.tabhost_two_pressed, true);
			itemThree.setImageResource(R.drawable.tabhost_three, false);
			itemFour.setImageResource(R.drawable.tabhost_four, false);
		} else if (id == R.id.itemThree) {
			itemOne.setImageResource(R.drawable.tabhost_one, false);
			itemTwo.setImageResource(R.drawable.tabhost_two, false);
			itemThree.setImageResource(R.drawable.tabhost_three_pressed, true);
			itemFour.setImageResource(R.drawable.tabhost_four, false);
		} else if (id == R.id.itemFour) {
			itemOne.setImageResource(R.drawable.tabhost_one, false);
			itemTwo.setImageResource(R.drawable.tabhost_two, false);
			itemThree.setImageResource(R.drawable.tabhost_three, false);
			itemFour.setImageResource(R.drawable.tabhost_four_pressed, true);
		}

		mocoopTabHostListener.changeItemListener(id);

	}

	public interface MocoopTabHostListener {
		public abstract void messageCountController(String tabName,String msg);
		
		public abstract void changeItemListener(int id);
		
		public abstract MocoopTabHost getMocoopTabHost();
	}
}



